package com.example.tests;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.nullValue;
import org.testng.annotations.Test;
import static org.hamcrest.Matchers.containsString;

import com.example.fw.Folders;

public class TestFolderCreation extends TestBase {
	
	@Test
	public void testFolderCreation() {
		String folder = "newfolder";
		Folders oldFolders = app.getFolderHelper().getFolders();
		assertThat(app.getFolderHelper().createFolder(folder),is(nullValue()));
		Folders newFolders = app.getFolderHelper().getFolders();
		assertThat(newFolders,equalTo(oldFolders.withAdded(folder)));
	}
	
	@Test
	public void testDuplicateFoldersCreation() {
		String folder = "newfolder3";
		Folders oldFolders = app.getFolderHelper().getFolders();
		assertThat(app.getFolderHelper().createFolder(folder), is(nullValue()));
		Folders newFolders = app.getFolderHelper().getFolders();
		assertThat(newFolders,equalTo(oldFolders.withAdded(folder)));
		assertThat(app.getFolderHelper().createFolder(folder),containsString("Duplicated folder name"));
		Folders newFolders2 = app.getFolderHelper().getFolders();
		assertThat(newFolders2,equalTo(newFolders));
	}
	
	@Test
	public void testTwoFoldersCreation() {
		String folder1 = "newfolder1";
		String folder2 = "newfolder2";
		Folders oldFolders = app.getFolderHelper().getFolders();
		assertThat(app.getFolderHelper().createFolder(folder1),is(nullValue()));
		Folders newFolders = app.getFolderHelper().getFolders();
		assertThat(newFolders,equalTo(oldFolders.withAdded(folder1)));
		assertThat(app.getFolderHelper().createFolder(folder2),is(nullValue()));
		Folders newFolders2 = app.getFolderHelper().getFolders();
		assertThat(newFolders2,equalTo(newFolders.withAdded(folder2)));
	}
}
